#include <bits/stdc++.h>
using namespace std;

int a[100010],n,m,v,l,d[100010],vv[100010],di[100010];

bool vis[100010];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    while(t--)
    {
        cin >> n >> m >> l >> v;
        for(int i = 1;i <= n;i++)
        {
            cin >> d[i] >> vv[i] >> a[i];
        }
        for(int i = 1;i <= m;i++)
        {
            cin >> di[i];
        }
        /*for(int i = l;i >= 1;i--)
        {
            if(vis[i])
            {
                a[i] = a[i + 1] - 1;
            }
            a[i] = a[i + 1];
        }*/
        int cnt = 0;
        for(int i = 1;i <= n;i++)
        {
            if(vv[i] > v && d[i] <= di[m])
            {
                cnt++;
            }
        }
        bool flag = 1;
        int sum = m - 1;
        for(int i = 1;i <= n;i++)
        {
            if(vv[i] > v)
            {
                if(d[i] <= di[m])
                {
                    flag = 0;
                }
            }
        }
        if(flag)
        {
            sum = m;
        }
        cout  << cnt << " "  << sum << endl;
    }
    return 0;
}
